//
//  DataHandel.m
//  Days
//
//  Created by lanou3g on 16/1/6.
//  Copyright © 2016年 dss. All rights reserved.
//

#import "DataHandel.h"
static DataHandel *_dataHandel = nil;
@implementation DataHandel
+(instancetype)sharedHandel{
    return [[self alloc]init];
    
}

+(instancetype)allocWithZone:(struct _NSZone *)zone{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (_dataHandel == nil) {
            _dataHandel  =[super allocWithZone:zone];
        }
    });
    return _dataHandel;
}

//根据网址得到数据的方法
-(void)getDataWithURL:(NSString *)url withBlock:(GETBLOCK) block{
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *datatask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
       
        id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            block(object);
            
        });
        
    }];
    
    
    //执行任务
    [datatask resume];
    
    
}




@end
